<template>
  <div>
    <h1>首页</h1>
    <el-button type="primary" @click="click">按钮</el-button>
    <el-button type="warning" @click="click1">按钮1</el-button>
    <el-button type="confirm" @click="click2">导出</el-button>
  </div>
</template>

<script>
import { saveAs } from 'file-saver';

// 生成文件内容
const fileContent = 'Hello, world!';

// 创建Blob对象
const blob = new Blob([fileContent], { type: 'text/plain;charset=utf-8' });
console.log(blob);
// 使用FileSaver.js保存文件
saveAs(blob, 'example.txt');

export default {
  name:"home",

  methods:{
    click(){
      this.$axios.get("/api/permission/list").then(res => {
        console.log(res);
      })
    },
    click1(){
      this.$axios.get("/api/user_role/list/"+2).then(res => {
        console.log(res);
      })
    },
    click2(){
        // 模拟文件内容
      const fileContent = 'Hello, world!';
      
      // 创建Blob对象
      const blob = new Blob([fileContent], { type: 'text/plain;charset=utf-8' });
      
      // 使用FileSaver.js保存文件
      // saveAs(blob, 'example.txt');
      // 提示用户选择文件保存位置
      const fileName = prompt('Please enter file name:', 'example.txt');
      if (fileName) {
        // 使用FileSaver.js保存文件
        saveAs(blob, fileName);
      } else {
        alert('File name cannot be empty!');
      }
  
    }
  },
  beforeMount(){

  }
}
</script>

<style>

</style>